package de.revdev.llt.bean.entities;

import de.revdev.llt.bean.entities.interfaces.EntityInterface;
import java.io.Serializable;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 *
 * @author f.lindermaier
 */
@Entity
@Table(name = "tbl_learnstatusfcb")
public class LearnStatusFCB implements Serializable, EntityInterface {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @ManyToOne
    @JoinColumn(name = "id_user")
    private User user;
    @OneToMany(mappedBy = "learnStatusFCB", cascade = CascadeType.ALL, orphanRemoval = true)
    private List<LearnStatusFC> learnStatusFC;
    @OneToOne
    private FileCardBox fileCardBox;

    @Override
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public List<LearnStatusFC> getLearnStatusFC() {
        return learnStatusFC;
    }

    public void setLearnStatusFC(List<LearnStatusFC> learnStatusFC) {
        this.learnStatusFC = learnStatusFC;
    }

    public FileCardBox getFileCardBox() {
        return fileCardBox;
    }

    public void setFileCardBox(FileCardBox fileCardBox) {
        this.fileCardBox = fileCardBox;
    }

    public int[] getCategories() {
        int[] result = new int[6];
        for (LearnStatusFC lsFC : getLearnStatusFC()) {
            result[lsFC.getLearnCategory().ordinal()]++;
        }
        return result;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof LearnStatusFCB)) {
            return false;
        }
        LearnStatusFCB other = (LearnStatusFCB) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "de.revdev.llt.bean.entities.LearnStatusFCB[ id=" + id + " ]";
    }
}
